<template>
  <el-container>
    <el-aside width="200px">
      <h2 class="logo">我的头条</h2>
      <el-menu
        :router="true"
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        background-color="#000"
        text-color="#fff"
      >
        <el-menu-item index="/postlist">
          <i class="el-icon-s-unfold"></i>
          <span slot="title">文章列表</span>
        </el-menu-item>
        <el-menu-item index="/editpost">
          <i class="el-icon-edit"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <img
          v-if="userInfo.head_img"
          :src="$axios.defaults.baseURL+userInfo.head_img"
          class="avatar"
          alt
        />
        <img v-else src="@/assets/logo.png" class="avatar" alt />
        <div class="nickname">{{userInfo.nickname}}</div>
        <div class="Sign_out" @click="logout">退出登录</div>
      </el-header>
      <el-main>
        <breadcrumb />
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import breadcrumb from "@/components/Breadcrumb";
export default {
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("user"))
    };
  },
  components: {
    breadcrumb
  },
  methods: {
    logout() {
      localStorage.removeItem("token");
      localStorage.removeItem("user");
      this.$message.success("退出成功");
      setTimeout(() => {
        this.$router.push("/login");
      }, 800);
    }
  }
};
</script>
<style lang="less" scoped>
.el-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background-color: #333;
  color: #fff;
  text-align: center;
  line-height: 60px;
  .avatar {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 50%;
  }
  .nickname {
    padding-left: 24px;
  }
  .Sign_out {
    padding: 8px 14px;
    color: #eee;
    cursor: pointer;
  }
}

.el-aside {
  background-color: #000;
  color: #fff;
  text-align: center;
  line-height: 200px;
  .el-menu {
    border-color: #333;
  }
  .logo {
    height: 60px;
    line-height: 60px;
    font-size: 20px;
    font-weight: bold;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
  // line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}
.el-container {
  height: 100vh;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
